package com.klhappy.houyuan.utils.library;

import java.util.List;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.klhappy.houyuan.R;
import com.klhappy.houyuan.bean.OnSelfGoodBean.GoodsProtys;

public class TagDrawableAdapter extends BaseAdapter {

	private Context mContext;
	private List<GoodsProtys> goodsProtyses;

	public TagDrawableAdapter(Context mContext, List<GoodsProtys> goodsProtyses) {
		super();
		this.mContext = mContext;
		this.goodsProtyses = goodsProtyses;
	}

	@Override
	public int getCount() {
		return goodsProtyses.size();
	}

	@Override
	public Object getItem(int position) {
		return goodsProtyses.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.tag_drawable_view, null);
			holder = new ViewHolder();
			holder.tagView = (TextView) convertView.findViewById(R.id.tag_view);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.tagView.setText(goodsProtyses.get(position).getD_cdesc());
		Drawable drawable;
		if (goodsProtyses.get(position).getD_val() != 4){
			drawable = mContext.getResources().getDrawable(R.drawable.tag_support);
		}else {
			drawable = mContext.getResources().getDrawable(R.drawable.tag_unsupport);
		}

		drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
		holder.tagView.setCompoundDrawables(drawable, null, null, null);
		return convertView;
	}

	static class ViewHolder {
		TextView tagView;
	}

}
